{* $Id$ *}
{include_core file="admin/lib/header.html" title="经销商商品列表"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">经销商商品列表<span>在这里对商品进行查看</span></h2>
  </div>
  <div class="search-level1 clearfix">
    <form action="goods/admin/store_goods" method="get">
      <input type="hidden" name="is_advenced" value="0">
      <input type="hidden" name="status" value="{$status}">
      <input {if $is_advenced == 1}style="display:none;"{/if} type="text" class="left" name="search_filter[title]" value="{$search_filter.title}">
      <button {if $is_advenced == 1}style="display:none;"{/if} type="submit" class="btn btn-success btn-sm left">搜索</button>
      <a href="javascript:void(0);" class="close js_advanced {if $is_advenced == 1}js_isOpen open{/if}">高级搜索<em></em></a>
    </form>
  </div>
  <div class="search-form js_advancedForm" {if $is_advenced == 0}style="display:none;"{/if}>
    <form action="goods/admin/store_goods" method="get" class="js_goodsSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="status" value="{$status}">
      <p>
        <label for="" class="search-f-label">商品标题：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[title]" value="{$search_filter.title}">
      </p>
      <p>
        <label for="" class="search-f-label">用户名称：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_name]" value="{$search_filter.user_name}">
      </p>
      <p>
      <label for="" class="search-f-label">添加时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  <!--start:列表-->
  <table class="list-table">
    <thead>
	  <tr>
	    <th>经销商</th>
	    <th style="width:60px;">封面</th>
	    <th style="min-width:150px;">商品信息</th>
        <th style="width:60px;">价格</th>
	    <th style="width:60px;">库存</th>
	    <th style="width:40px;">销量</th>
	    <th style="min-width:60px;">操作</th>
	  </tr>
    </thead>
    <tbody>
      {foreach $store_goods_list as $k=>$v}
      {if $v.goods_info.cover}
      {$cover = _uri('attachment', $v.goods_info.cover, 'path')}
      {$image = _image($cover, 'small')}
      {/if}
      <tr data-goods_id="{$v.goods_id}" data-store_id="{$v.store_id}"  {if $k%2 == 1} class="bg-gray"{/if}>
        <td>
          {_uri('user', (int)$v.user_id, 'user_name')}
        </td>
        <td>
          <img width="70" src="{$image}">
        </td>
        <td>
          商品分类：{_uri('category', $v.goods_info.category_id, 'title')}<br />
          商品标题：{$v.goods_info.title}
        </td>
        <td>{goods_helper::get_store_price_by_id($v.store_id, $v.goods_id)}</td>
        <td>{goods_helper::get_store_stock_by_id($v.store_id, $v.goods_id)}</td>
        <td>{$v.sale_count}</td>
        <td>
          <a class="btn btn-xs btn-primary js_skuInfo">SKU信息</a>
        </td>
      </tr>
      {foreachelse}
      <tr><td class="txtleft" colspan="11">暂无数据</td></tr>
      {/foreach}
    </tbody>
    {if $status == 1}
    <tfoot></tfoot>
    {/if}
  </table>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
<script>
$(function(){
  $('.js_skuInfo').click(function(){
    var goodsId = $(this).closest('tr').data('goods_id');
    var storeId = $(this).closest('tr').data('store_id');
    var html = '';
    $.ajax({
      type: "POST",
      url: siteUrl+"/goods/admin/store_goods/get_sku_list",
      data: { goods_id:goodsId, store_id:storeId },
      async: false,
      cache: false,
      success: function(data){
        html = data;
      }
    })
    ace.dialog({
      title: 'SKU信息',
      content:html,
      ok:function(){
        qDialog.close()
      },
      cancel:function(){
        return true;
      }
    });
  })
  
  // 高级搜索
  $('.js_advanced').click(function(e){
    e.preventDefault();
    var thisObj = $(this);
    var outBox  = thisObj.closest('form');
    if (thisObj.hasClass('js_isOpen')) {
      thisObj.removeClass('js_isOpen open');
      outBox.find('input').show();
      outBox.find('button').show();
      $('.js_advancedForm').hide();
    } else {
      thisObj.addClass('js_isOpen open');
      outBox.find('input').hide();
      outBox.find('button').hide();
      $('.js_advancedForm').show();
    }
  });
  
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });
});
// 关闭弹窗
function closeDiv(){
  $('.js_discountDiv').next().css('display', 'none');
  $('.js_discountDiv').css('display', 'none');
  location.href = location.href;
}
</script>
{include_core file="admin/lib/footer.html"}